import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { DAGGraph, DockerTask, DockerfileCreate, DockerfileResponse, GenYaml, GitAuth, GitConfig, GitMonitor, GitPipelinetask, SubModule } from "@api/git";
import { Observable } from "rxjs";

@Injectable()
export class GitManagerService {
    constructor(private readonly http_: HttpClient) {}
    getGitConfig():Observable<GitConfig[]>{
        return this.http_.get<GitConfig[]>("/git/repo/get")
    }
    createGitConfig(gitconfig:GitConfig):Observable<GitConfig>{
        return this.http_.post<GitConfig>("/git/repo/create",gitconfig)
    }
    deleteGitconfig(id:number):Observable<boolean>{  
        return this.http_.delete<boolean>(`/git/repo/delete/${id}`)
    }
    getGitConfigByid(id:number):Observable<GitConfig>   {
        return this.http_.get<GitConfig>(`/git/repo/getbyid/${id}`)
    }


    getGitAuth():Observable<GitAuth[]>{
        return this.http_.get<GitAuth[]>("/git/auth")
    }
    createGitAuth(gitauth : GitAuth):Observable<GitAuth>{
        return this.http_.post<GitAuth>("/git/auth",gitauth)
    }
    deleteGitAuth(id:number):Observable<boolean>{  
        return this.http_.delete<boolean>(`/git/auth/delete/${id}`)
    }

    getGitMonitor():Observable<GitMonitor[]>{
        return this.http_.get<GitMonitor[]>("/git/monitor")
    }

    GetAllPipeTask():Observable<GitPipelinetask[]>{
        return this.http_.get<GitPipelinetask[]>("/git/citask/all")
    }
    GetAllPipeTaskByGitid(gitid:number):Observable<GitPipelinetask[]>{
        return this.http_.get<GitPipelinetask[]>(`/git/citask/gitid/${gitid}`)
    }

    DockerTasksByGitHash(hash :string):Observable<DockerTask[]>{
        return this.http_.get<DockerTask[]>(`/git/dockertask/${hash}`)
    }

    SubModuleList(gitid :number):Observable<SubModule[]>{
        return this.http_.get<SubModule[]>(`/git/project/submodule/list/${gitid}`)
    }
    SubModuleDockerfile(gitid:number ,submodule:string):Observable<DockerfileResponse>{
        return this.http_.post<DockerfileResponse>(
            "/git/project/submodule/dockerfile",
            {
                "gitid":gitid,
                "submodule":submodule
            }
        )
    }
    SubModuleDockerfileCreate(data : DockerfileCreate):Observable<Object>{
        return this.http_.post<DockerfileResponse>("/git/project/submodule/createdockerfile",
        data)
    }
    SubModuleAutoGenDockerfile(gitid:number,submodule:string)   :Observable<DockerfileResponse>{
        return this.http_.post<DockerfileResponse>(
            "/git/project/submodule/gendocker",
            {
                "gitid":gitid,
                "submodule":submodule
            }
        )
    }

    SubModuleAutoGenK8sYaml(genyaml:GenYaml):Observable<GenYaml>{
        return this.http_.post<GenYaml>(
            "/git/project/submodule/genyaml",
            genyaml
        )
    }



    DagTaskCreate(dagtask : DAGGraph):Observable<DAGGraph>{
        return this.http_.post<DAGGraph>(
            "/git/dagtask/create",
            dagtask    
        )
    }
}